/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.gov.cemaden.library.dao.previsao;

import br.gov.cemaden.library.model.previsao.AquisicaoPrecipitacao;
import br.gov.cemaden.library.model.previsao.PrevisaoPrecipitacao;
import java.util.Date;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

/**
 *
 * @author alan.oliveira
 */
public class PrevisaoPrecipitacaoDAO {
    
    private final EntityManager em;

    public PrevisaoPrecipitacaoDAO(EntityManager em) {
        this.em = em;
    }
    
    public PrevisaoPrecipitacao find(AquisicaoPrecipitacao aquisicao, Date datahora, Double latitude, Double longitude) {        
        
        TypedQuery<PrevisaoPrecipitacao> query;
        query = em.createQuery("FROM " + PrevisaoPrecipitacao.class.getName() + " WHERE aquisicao = :aquisicao AND datahora = :datahora AND latitude = :latitude AND longitude = :longitude", 
                PrevisaoPrecipitacao.class);
        query.setParameter("aquisicao", aquisicao);
        query.setParameter("datahora", datahora);
        query.setParameter("latitude", latitude);
        query.setParameter("longitude", longitude);
        
        return query.getSingleResult();
        
    }
    
}
